﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Models;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline;
using ThouShaltNotBrick.PipelineExtension.Readers;

namespace ThouShaltNotBrick.PipelineExtension
{
    [ContentTypeWriter]
    public sealed class BrickTypesContentTypeWriter : ContentTypeWriter<BrickTypesData>
    {
        #region Overriden Methods
        protected override void Write(ContentWriter pOutput, BrickTypesData pValue)
        {
            // NUMBER OF BRICK TYPES (int)
            //   NAME (string)
            //   NUMBER OF BRICK STATES (int)
            //     NAME (string)

            List<BrickTypeData> brickTypeList = pValue.GetBrickTypes();
            pOutput.Write(brickTypeList.Count);
            foreach (BrickTypeData brickType in brickTypeList)
            {
                pOutput.Write(brickType.Name);

                List<string> brickStateList = brickType.GetBrickStates();
                pOutput.Write(brickStateList.Count);
                foreach (string brickStateName in brickStateList)
                {
                    pOutput.Write(brickStateName);
                }
            }
        }

        public override string GetRuntimeReader(TargetPlatform pTargetPlatform)
        {
            return typeof(BrickTypesContentTypeReader).AssemblyQualifiedName;
        }

        public override string GetRuntimeType(TargetPlatform pTargetPlatform)
        {
            return typeof(BrickTypesData).AssemblyQualifiedName;
        }
        #endregion
    }
}